import {singer_music} from '@/network/api'
import http from '@/network/http'

export default{
  namespaced:true,
  state:{
    headInfo:{},
    musicList:[],
    loading:false
  },
  mutations:{
    setSingerInfo(state,payload){
      state.headInfo=payload.headInfo
      state.musicList=payload.musicList
    },
    setLoading(state,payload){
      state.loading=payload
    },
  },
  actions:{
    async getSingerMusicList(context,payload){
      context.commit('setLoading',true)
      let {artist,hotSongs}=await http.get(singer_music,payload)
      const musicList = hotSongs.map(item=>({
        id: item.id, //id
        title: item.name, //歌名
        ar: item.ar.map((arItem) => arItem.name), //歌手
        al: {
          //专辑
          name: item.al.name,
          picUrl: item.al.picUrl,
        },
      }));
      context.commit('setSingerInfo',{headInfo:{img:artist.picUrl,name:artist.name},musicList})
      context.commit('setLoading',false)
    }
  }
}